﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DslamPort.Models;

namespace DslamPort.Controllers
{
    public class xuatdlController : Controller
    {
        //
        // GET: /xuatdl/

        public ActionResult Index()
        {
            return View();
        }

        //public static List<xuatdulieuModel> dslamport_global { get; set; }
        //public static List<DslamPortModel> detail_dslamport_global { get; set; }


        //        Mã Gói Cước	Tốc Độ
        //F100T100P0_B1	10M
        //F100T100P1_B1	10M
        //F300T300P0_B0	14M
        //F300T300P1_B0	14M
        //F80T80P0_B0	8M
        //F80T80P1_B0	8M
        //FiberF2EM	50M
        //FiberF2E	50M
        //FiberF2M	100M
        //FiberF3M	100M
        //FiberVKS_18M	18M
        //FiberF1	100M
        //F300T300P1_B0	30M
        //F300T300P0_B0	30M
        //FiberF1P	100M
        //F140T140P0_B1	14M
        //F140T140P1_B1	14M

        public void Export_Excel(string type)
        {

            if (type == "4")
            {
                List<xuatdulieuModel> dslamport_global = xuatdulieuModel.getDslamPort_4thamso();
                // dslamport_global = DslamPort;
                Response.AddHeader("content-disposition", "attachment; filename=bao_cao_4thamso.xls");
                Response.ContentType = "application/ms-excel";
                Response.ContentEncoding = System.Text.Encoding.Unicode;
                Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());

                Response.Write("<h3>BÁO CÁO CỔNG DSLAM 4 THAM SỐ </h3>");
                Response.Write("<BR>");
                Response.Write("<Table border='1' bgColor='#ffffff' borderColor='#000000' cellSpacing='0' cellPadding='0' style='font-size:10.0pt; font-family:Calibri; background:white;'> <TR>");
                Response.Write("<td><b>ID cổng</b></td>");
                Response.Write("<td><b>SYSTEM ID</b></td>");
                Response.Write("<td><b>ID loại cổng 1-ADSL/2-SHDSL</b></td>");
                Response.Write("<td><b>Thuộc Frame nào</b></td>");
                Response.Write("<td><b>Thuộc Slot nào</b></td>");
                Response.Write("<td><b>Thuộc Port nào trên Slot</b></td>");
                Response.Write("<td><b>ID trạng thái của cổng</b></td>");
                Response.Write("<td><b>Tham số Sub Interface</b></td>");
                Response.Write("<td><b>Phiến thuê bao</b></td>");
                Response.Write("<td><b>Đôi dây thuê bao</b></td>");
                Response.Write("<td><b>Phiến tổng đài</b></td>");
                Response.Write("<td><b>Đôi dây tổng đài</b></td>");
                Response.Write("<td><b>Tham số VPI/SVLAN</b></td>");

                Response.Write("<td><b>Tham số VCI/CVLAN </b></td>");
                Response.Write("<td><b>ID các dịch vụ chạy trên cổng, cách nhau bởi dấu ';'</b></td>");
                Response.Write("<td><b>Mã dịch vụ(Account MyTV, số ADSL(account) MegaVNN, Mã </b></td>");
                Response.Write("<td><b>Tốc độ </b></td>");
                Response.Write("<td><b>IP</b></td>");
                Response.Write("</TR>");
                int sum = 0;
                for (int i = 0; i < dslamport_global.ToArray().Length; i++)
                {

                    // sum = Convert.ToInt32(dslamport_global[i].cong) + Convert.ToInt32(dslamport_global[i].sum_port_lock) + Convert.ToInt32(dslamport_global[i].sum_port_stop);
                    Response.Write("<TR>");
                    Response.Write("<td>" + dslamport_global[i].cong + "</td>");
                    Response.Write("<td>" + dslamport_global[i].mathietbi + "</td>");
                    Response.Write("<td>1</td>");
                    Response.Write("<td>0</td>");
                    Response.Write("<td>" + dslamport_global[i].slot + "</td>");
                    Response.Write("<td>" + dslamport_global[i].port + "</td>");
                    string tt = "3";
                    if (dslamport_global[i].trangthai == "2")
                    {
                        tt = "5";
                    }

                    if (dslamport_global[i].trangthai == "1")
                    {
                        tt = "4";
                    }
                    Response.Write("<td>" + tt + "</td>");
                    Response.Write("<td>00</td>");
                    int phientongdai = 0;
                    try
                    {
                        string ma = dslamport_global[i].mathietbi;
                        int tam = int.Parse(ma.Substring(ma.Length - 1));
                        phientongdai = tam - 1 + int.Parse(dslamport_global[i].slot);
                    }
                    catch (System.Exception ex)
                    {
                        phientongdai = 0;
                    }
                    Response.Write("<td>" + phientongdai + "</td>");//Phiến tổng đài = tham số slot + (ký tự cuối trong sysid-1)
                    //int doiday = 0;
                    Response.Write("<td>" + dslamport_global[i].port + "</td>");//đôi dây tổng đài = tham số port

                    Response.Write("<td>" + phientongdai + "</td>");
                    Response.Write("<td>" + dslamport_global[i].port + "</td>");


                    Response.Write("<td>" + dslamport_global[i].vpi + "</td>");
                    Response.Write("<td>" + dslamport_global[i].vci + "</td>");
                    //trang thai
                    string trangthai = "";
                    if (dslamport_global[i].accinternet != "")
                    {
                        trangthai += "1";
                        trangthai += ";";
                    }
                    if (dslamport_global[i].accmytv != "")
                    {

                        trangthai += "3";
                    }
                    Response.Write("<td>" + trangthai + "</td>");
                    //trang thai cong chua sua
                    //Response.Write("<td>" + dslamport_global[i].vpi + "</td>");
                    string a = "";
                    if (dslamport_global[i].accinternet != "")
                    {
                        a += dslamport_global[i].accinternet;
                        a += ";";
                    }
                    if (dslamport_global[i].accmytv != "")
                    {

                        a += dslamport_global[i].accmytv;
                    }
                    Response.Write("<td>" + a + "</td>");
                    string gc = dslamport_global[i].goicuoc;
                    switch (gc)
                    {
                        case "F100T100P0_B1":
                            gc = "10M";
                            break;
                        case "F100T100P1_B1":
                            gc = "10M";
                            break;
                        case "F300T300P0_B0":
                            gc = "30M";
                            break;
                        case "F300T300P1_B0":
                            gc = "30M";
                            break;
                        case "F80T80P0_B0":
                            gc = "8M";
                            break;

                        case "F80T80P1_B0":
                            gc = "8M";
                            break;
                        case "FiberF2E":
                            gc = "50M";
                            break;
                        case "FiberF2EM":
                            gc = "50M";
                            break;
                        case "FiberF2M":
                            gc = "100M";
                            break;
                        case "FiberF3M":
                            gc = "100M";
                            break;
                        case "FiberVKS_18M":
                            gc = "18M";
                            break;
                        case "FiberF1":
                            gc = "100M";
                            break;
                        //case "F300T300P1_B0":
                        //    gc = "30M";
                        //    break;
                        //case "F300T300P0_B0":
                        //    gc = "30M";
                        //    break;

                        case "MegaBasic":
                            gc = "3M";
                            break;
                        case "MegaEasy":
                            gc = "4M";
                            break;
                        case "MegaFamily":
                            gc = "5M";
                            break;
                        case "MegaMaxi":
                            gc = "8M";
                            break;
                        case "Megapro":
                            gc = "10M";
                            break;
                        

                        case "FiberF1P":
                            gc = "100M";
                            break;
                        case "F140T140P0_B1":
                            gc = "14M";
                            break;
                        case "F140T140P1_B1":
                            gc = "14M";
                            break;
                        default:
                            gc = "0M";
                            break;



                    }

                    //                    Mã Gói Cước	Tốc Độ
                    //	10M
                    //F100T100P1_B1	10M
                    //F300T300P0_B0	14M
                    //


                    //
                    //	50M
                    //	100M
                    //	100M
                    //	18M
                    //	100M
                    //	30M
                    //	30M
                    //FiberF1P	100M
                    //F140T140P0_B1	14M
                    //F140T140P1_B1	14M

                    Response.Write("<td>" + gc + "</td>");
                    Response.Write("<td>" + dslamport_global[i].ip + "</td>");
                }

                Response.Write("</Table>");
                Response.Flush();
                Response.End();
            }
            else
            {
                //else
                List<xuatdulieuModel> dslamport_global = xuatdulieuModel.getDslamPort_7thamso();
                // dslamport_global = DslamPort;
                Response.AddHeader("content-disposition", "attachment; filename=bao_cao_7thamso.xls");
                Response.ContentType = "application/ms-excel";
                Response.ContentEncoding = System.Text.Encoding.Unicode;
                Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
                Response.Write("<h3>BÁO CÁO CỔNG DSLAM 7 THAM SỐ </h3>");
                Response.Write("<BR>");
                Response.Write("<Table border='1' bgColor='#ffffff' borderColor='#000000' cellSpacing='0' cellPadding='0' style='font-size:10.0pt; font-family:Calibri; background:white;'>  <TR>");
                Response.Write("<td><b>ID cổng</b></td>");
                Response.Write("<td><b>SYSTEM ID</b></td>");
                Response.Write("<td><b>ID loại cổng 1-ADSL/2-SHDSL</b></td>");
                Response.Write("<td><b>Thuộc Frame nào</b></td>");
                Response.Write("<td><b>Thuộc Slot nào</b></td>");
                Response.Write("<td><b>Thuộc Port nào trên Slot</b></td>");
                Response.Write("<td><b>ID trạng thái của cổng</b></td>");
                Response.Write("<td><b>Tham số Sub Interface</b></td>");
                Response.Write("<td><b>Phiến thuê bao</b></td>");
                Response.Write("<td><b>Đôi dây thuê bao</b></td>");
                Response.Write("<td><b>Phiến thuê bao</b></td>");
                Response.Write("<td><b>Đôi dây tổng đài</b></td>");
                Response.Write("<td><b>Tham số Slot trên visa</b></td>");
                Response.Write("<td><b>Tham số Port trên Visa</b></td>");


                //Response.Write("<td><b>Tham số VPI/SVLAN</b></td>");

                //Response.Write("<td><b>Tham số VCI/CVLAN </b></td>");
                Response.Write("<td><b>ID các dịch vụ chạy trên cổng, cách nhau bởi dấu ';'</b></td>");
                Response.Write("<td><b>Mã dịch vụ(Account MyTV, số ADSL(account) MegaVNN, Mã </b></td>");
                Response.Write("<td><b>IP</b></td>");
                Response.Write("</TR>");
                // int sum = 0;
                for (int j = 0; j < dslamport_global.ToArray().Length; j++)
                {

                    Response.Write("<TR>");
                    Response.Write("<td>" + dslamport_global[j].cong + "</td>");
                    Response.Write("<td>" + dslamport_global[j].mathietbi + "</td>");
                    Response.Write("<td>1</td>");
                    Response.Write("<td>0</td>");
                    Response.Write("<td>" + dslamport_global[j].slot + "</td>");
                    Response.Write("<td>" + dslamport_global[j].port + "</td>");
                    string tt2 = "3";
                    if (dslamport_global[j].trangthai == "2")
                    {
                        tt2 = "5";
                    }
                    else
                        if (dslamport_global[j].trangthai == "1")
                        {
                            tt2 = "4";
                        }
                    Response.Write("<td>" + tt2 + "</td>");
                    Response.Write("<td>00</td>");
                    int phientongdai = 0;
                    try
                    {
                        string ma = dslamport_global[j].mathietbi;
                        int tam = int.Parse(ma.Substring(ma.Length - 1));
                        phientongdai = tam - 1 + int.Parse(dslamport_global[j].slot);
                    }
                    catch (System.Exception ex)
                    {
                        phientongdai = 0;
                    }
                    Response.Write("<td>" + phientongdai + "</td>");//Phiến tổng đài = tham số slot + (ký tự cuối trong sysid-1)
                    //int doiday = 0;
                    Response.Write("<td>" + dslamport_global[j].port + "</td>");//đôi dây tổng đài = tham số port

                    Response.Write("<td>" + phientongdai + "</td>");
                    Response.Write("<td>" + dslamport_global[j].port + "</td>");

                    Response.Write("<td>00</td>");
                    Response.Write("<td>00</td>");
                    //Response.Write("<td>" + dslamport_global[J].vpi + "</td>");
                    //Response.Write("<td>" + dslamport_global[J].vci + "</td>");


                    //trang thai cong chua sua
                    //trang thai
                    string trangthai = "";
                    if (dslamport_global[j].accinternet != "")
                    {
                        trangthai += "1";
                        trangthai += ";";
                    }
                    if (dslamport_global[j].accmytv != "")
                    {

                        trangthai += "3";
                    }
                    Response.Write("<td>" + trangthai + "</td>");
                    string a2 = "";
                    if (!string.IsNullOrEmpty(dslamport_global[j].accinternet))
                    {
                        a2 += dslamport_global[j].accinternet;
                    }
                    if (!string.IsNullOrEmpty(dslamport_global[j].accmytv))
                    {
                        a2 += ";";
                        a2 += dslamport_global[j].accmytv;
                    }
                    Response.Write("<td>" + a2 + "</td>");
                    Response.Write("<td>" + dslamport_global[j].ip + "</td>");
                }

                Response.Write("</Table>");
                Response.Flush();
                Response.End();
                //else_end
            }






        }
    }
}
